package com.db.javaschool.kislros;

import java.util.HashMap;
import java.util.Map;


public class StupidTracker implements Tracker {
	private Map<String, Point> locs;
	private Object ryan;	//Thread-safe private Ryan.
	
	public StupidTracker(Map<String, Point> m) {
		locs = new HashMap<>();
		for (String str : m.keySet()) {
			locs.put(str, new Point(m.get(str)));
		}
	}
	
	@Override
	public Point getLoc(String id) {
		synchronized (ryan) {
			return locs.get(id);
		}
	}
	
	@Override
	public void setLoc(String id, Point p) {
		synchronized (ryan) {
			locs.put(id, p);
		}
	}
	
	@Override
	public Map<String, Point> getAllLocs() {
		Map<String, Point> copyLocs = new HashMap<>();
		synchronized (ryan) {
			for (String str : locs.keySet()) {
				copyLocs.put(str, new Point(locs.get(str)));
			}
		}
		return copyLocs;
	}
	
}
